<template>
  <div>
    <el-table
      :data="tableData"
      style="width: 100%"
      :row-class-name="tableRowClassName">
      border
      <el-table-column
        prop="id"
        label="id"
        width="200">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="200">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="电话"
        width="200">
      </el-table-column>
      <el-table-column
        prop="email"
        label="邮件"
        width="200">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="创建时间"
        width="200">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址">
      </el-table-column>
    </el-table>
    <!--分页插件-->
    <!--
    layout:布局
    :total:总条数 应该从data()中拿取
    :current-page:当前页
    :page-size：每页条数
     @current-change：监听页码变化
    -->
    <el-pagination
      align="right"
      background
      layout="prev, pager, next"
      :total="totals">
      :current-page="currentPage"
      :page-size="pageSize"
      @current-change:"gotoPage">
    </el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      totals:0,
      currentPage:1,
      pageSize:5,
      tableData: []
    }
  },
  methods: {
    getUserList() {
      let para = {"currentPage":this.currentPage,"pageSize":this.pageSize}
      this.$http.post("/user/list",para)
        .then(result => {
          this.tableData = result.data.data;
          this.totals = result.data.totals;
        })
        .catch(result => {
          alert(result)
          alert("大哥你网不好吧")
        })
    },
    gotoPage(curr) {
      this.currentPage = curr;
      this.getUserList();
    },
    tableRowClassName({row, rowIndex}) {
      if (rowIndex === 0) {
        return 'warning-row';
      } else if (rowIndex === 2) {
        return 'success-row';
      } else if (rowIndex === 0) {
        return 'warning-row';
      }
      return '';
    }
  },
  mounted() {
    this.getUserList();
  }
}
</script>

<style>
.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}
</style>
